-- || Created by Unlimited

DamageLog = inherit(Singleton)

function DamageLog:constructor()
	damagelog = self
	
	self.m_Data = {}

	addEventHandler("onPlayerWasted", root, bind(self.wasted,self))
	addEventHandler("onPlayerDamage", root, bind(self.damage,self))
	
end

function DamageLog:wasted(_, attacker)
	if not self.m_Data[attacker] then
		self:addPlayer(attacker)
	end
	self.m_Data[attacker].kills = self.m_Data[attacker].kills + 1
	setElementData(attacker, "Kills", self.m_Data[attacker].kills)
end

function DamageLog:damage(attacker, _, _, loss)
	if not self.m_Data[attacker] then
		self:addPlayer(attacker)
	end
	self.m_Data[attacker].damage = self.m_Data[attacker].damage + loss
	setElementData(attacker, "Damage", self.m_Data[attacker].damage)	
end

function DamageLog:addPlayer(player)
	self.m_Data[player] = {}
	local sP = self.m_Data[player]
	sP.kills = getElementData(player, "Kills") or 0
	sP.damage = 0
end